fix(browser): catch malformed URL TypeError and map to exit 5 VALIDATION_ERROR#274
Conversation
|
✅ This PR is linked to an issue assigned to @sandman-sh — thanks! The |
Walkthrough
ChangesBrowser URL validation
Estimated code review effort: 2 (Simple) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
zeshi-du
left a comment
There was a problem hiding this comment.
LGTM — try-block scoped to the single new URL() call, error shape matches the adjacent protocol branch (VALIDATION_ERROR → exit 5), test asserts the exact exit code and the no-spawn guard. Correct and minimal.
Closes #276
Summary
Fixes un-guarded
new URL(url)call inopenInBrowser(src/lib/browser.ts) so malformed URLs return a clean CLIVALIDATION_ERROR(exit code 5) instead of crashing with an unhandled Node.jsTypeError.Problem
When
openInBrowser(url)receives a malformed or unparseable URL string (e.g."not a url"),new URL(url)throws a raw Node.jsTypeError: Invalid URL.Because this call was not wrapped in a
try/catchblock:file://already threwVALIDATION_ERROR(exit 5), creating an inconsistent error contract for bad inputs.Solution
Wrap
new URL(url)in atry/catchblock inopenInBrowser:Test Coverage
Updated src/lib/browser.test.ts to assert that malformed URL inputs throw
ApiErrorwithexitCode = 5. All unit tests pass.